# -*- encoding: utf-8 -*-
"""
File Name: launch
Description:
Author : 'lirui'
date: 2024/7/31
Contact: marjey_lee@163.com
Change Activity:
2024/7/31:
"""
from modules.blk.cmdb.cmdb_service import CMDBService

_TEMPLATE = """
#  视频会议运维网页转发
    server {   # {location}
        listen {nginx_port};
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass {ip}:{port};
    }

"""


def _main():
    data = CMDBService().select('remote_meeting_forward')
    d = data['data']['info']
    cfg = '##### remote meeting port forward start ####'
    for item in d:
        if len(item['ip']) < 3:
            continue
        if item['protocol'] == 'HTTP':
            port = 80
        else:
            port = 443
        content = rf"""
    server ( #  {item['branch_name']}
        listen {item['nginx_port']};
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass {item['ip']}:{port};
    )
""".replace('(', '{').replace(')', "}")
        cfg = cfg + content
    cfg = cfg + '##### remote meeting port forward end ####'
    print(cfg)


if __name__ == '__main__':
    _main()
